import router from '@system.router';
import prompt from '@system.prompt';

export default {
    data: {
        loading: false
    },

    async toGame(){
        this.loading = true

        //验证获取权限后，进入页面
        let res = await FeatureAbility.startAbilityForResult({bundleName:'com.myharos.fingerguessing',
            abilityName:'com.myharos.fingerguessing.Permission'})
        let data = JSON.parse(res.data)
        if(data.parameters.res){
            //启动service去连接另一设备
            let result = await FeatureAbility.callAbility({
                bundleName:'com.myharos.fingerguessing',
                abilityName:'com.myharos.fingerguessing.connect',
                messageCode: 0,
                abilityType: 0,
                syncOption: 0
            })
            if(result == 'true'){
                //connect sucess
                router.push({uri: 'pages/play/play'})
            }else{
                prompt.showToast({message:'connect fail'})
            }
        }else{
            prompt.showToast({message:'no permission'})
        }
        this.loading = false
    }
}
